package com.hzlh.common.util;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class HttpGetInterface {
	public static String callQtService(String servicePath){
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String result="";
			HttpGet httpGet = new HttpGet(servicePath);
			httpGet.addHeader("Content-Type", "text/html;charset=UTF-8");
			CloseableHttpResponse response1 = null;
			try {
				response1 = httpclient.execute(httpGet);
				if(response1.getStatusLine().getStatusCode()==200){
					HttpEntity entity1 = response1.getEntity();
//			        InputStream s = entity1.getContent();
			        result = EntityUtils.toString(entity1);
				}
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				try {
					response1.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				try {
					httpclient.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}	

		return result;
	}
}
